<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@page import="Logic.Authorizer"%>
<%@page import="servlet.ProcessesDropDown"%>
<%@page import="servlet.ProcessesRecDropDown"%>
	<%@ page import="java.sql.*" %>
	<%@ page import="java.io.*" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
	if (session.getAttribute("name") == null) {
		response.sendRedirect("login.jsp");
	} else {
		if (!Authorizer.checkRole("2", session.getAttribute("role")
				.toString())) {
			response.sendRedirect("nopermission.jsp");
		}
	}
	if (request.getParameter("result")!= null) {
		if (request.getParameter("result").equals("1")) { %>
		<script>
			alert('Upload successful!');
		</script>
		<% }
	else { %>
		<script>
		alert('Error uploading file!');
		</script>
	<%}
	}
%>
<jsp:include page="t_header.jsp" />

<!--  <div class="breadcrumbs_container">
	<article class="breadcrumbs"> <a href="Proc_NewProcess.jsp">Manage Processes</a>
	<div class="breadcrumb_divider"></div>
	<a class="current">New Procedure</a> 
	</article>
</div> -->
<jsp:include page="header.html" />

<!-- Declare sidebar -->
<jsp:include page="t_sidebarProcess.jsp" />

<!-- Main Content -->
<body>
<section id="main" class="column">
<article class="module width_3_quarter">
	<form id="SingleNewProcedure" action="SingleNewProcedure" method="post" enctype="multipart/form-data">
	<header><h3>Add New Procedure to a Process</h3></header>
	<div class="module_content">
	<fieldset>
	<label>Select the  process that you wish to add a procedure</label>
					<select name="PN" id="PN" style="width: 80%">
						<%
							ProcessesDropDown PDD = new ProcessesDropDown(out);
							PDD.doGet(request, response);
						%>
					</select>
					</fieldset>
					<fieldset style="width: 48%; float: left; margin-right: 3%;">
					<label>Code</label>
					<input type='text' id="Code" name="Code" style="width: 80%" onChange="CheckProcess(this.value, this)">
					</fieldset>
					<fieldset style="width: 48%; float: left;">
					<label>Procedure Name</label>
					<input type='text' id="ProcedureName" name="ProcedureName" style="width: 80%" onChange="CheckProcess(this.value, this)">
					</fieldset>
					<fieldset style="width:630px; float: left; margin-bottom: 2%;">
					<label>Procedure File</label>
					<div style="width: 612px; margin: 0 auto;" >
					<input id="ProcedureFile" type="file" name="ProcedureFile" style="width: 85%">
					</div>
					</fieldset>
					<div class="clear">
					</div>
					<fieldset>
					<label>Effective Date</label>
					<input name="effectivedate" type="text" id="inputField" style="width: 80%" readonly="readonly"/>
					</fieldset>
					<div class="clear">
					</div>
					</div>
					<footer>
					<div class="submit_link">
					<input id="Add" type="submit" value="Add" onclick="return verifyData()" class="alt_btn">
					<input id="Clear" type="reset" value="Clear" onclick="Clear()" class="alt_btn"/>
					</div>
					</footer>
	
    </form>

   </article>
    
<script type="text/javascript">

function verifyData(){
if(CheckSpecial()==false)
{
	alert('Please ensure that all entered text does not contain special characters. ');
	return false;
}
else{
     if ( $('#ProcedureFile').val() == ""||$('#Code').val() == ""||$('#ProcedureName').val() == ""||$('#inputField').val() == "") {
          alert('Please ensure that all fields are filled in and document is selected.');
 		  return false;
     }
     /*else {
           //alert('File selected: ' + $('#ProcedureFile').val());
        	var form = document.getElementById('SingleNewProcedure');		    
        	form.action="SingleNewProcedure.jsp?PN="+document.getElementById('PN').value+"&ProcedureName="+document.getElementById('ProcedureName').value+"&Code="+document.getElementById('Code').value+"&EDate="+document.getElementById('inputField').value;
        	form.submit();

        
   		  return true;
     }*/
     }
     }
     
     function Clear(){
		document.getElementById('SingleUpload').reset();	
		return false;
	 }
     
     function CheckProcess(str, object)
     {
         var iChars = "~`!#$%^*+=[]\\\';,/{}|\":<>?";
     	object.style.backgroundColor="#FFF";
         for (var i = 0; i < str.length; i++) {
            if (iChars.indexOf(str.charAt(i)) != -1) {
     	       object.style.backgroundColor="#FA5858";
                alert ("Special characters like ~`!#$%^*+=[]\\\';,/{}|\":<>? \nare not allowed!\n");
                object.focus();
                object.select();
      		   break;
            }
         }
     }
     
     function CheckSpecial()
	{
	var iChars = "~`!#$%^*+=[]\\\';,/{}|\":<>?";
	var CodeObj=document.getElementById('Code').value;
	var ProcedureObj=document.getElementById('ProcedureName').value;
	var ConcateVal=CodeObj+ProcedureObj;
	var result=true;
    for (var i = 0; i < ConcateVal.length; i++) {
       if (iChars.indexOf(ConcateVal.charAt(i)) != -1) {
	      result=false;
	      break;
       	}
       
   	 	}
    return result;
	}
</script>
<div class="spacer"></div>
</section>
	<!-- Declare closing tags -->
	<jsp:include page="t_footer.jsp" />



